﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <ControlTemplate x:Key="ComboBoxToggleButton"
                     TargetType="{x:Type ToggleButton}">
        <Grid>
            <Border Grid.Column="0"
                    BorderBrush="White"
                    BorderThickness="1,0,0,0">
                <Border.Background>
                    <SolidColorBrush Color="#38004D" />
                </Border.Background>
            </Border>
            <Path x:Name="Arrow"
                  HorizontalAlignment="Center"
                  VerticalAlignment="Center"
                  Data="M 0 0 L 4 4 L 8 0 Z">
                <Path.Fill>
                    <SolidColorBrush Color="White" />
                </Path.Fill>
            </Path>
        </Grid>
    </ControlTemplate>

    <Style x:Key="{x:Type ComboBox}"
           TargetType="{x:Type ComboBox}">
        <Setter Property="SnapsToDevicePixels"
                Value="true" />
        <Setter Property="OverridesDefaultStyle"
                Value="true" />
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility"
                Value="Auto" />
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility"
                Value="Auto" />
        <Setter Property="ScrollViewer.CanContentScroll"
                Value="true" />
        <Setter Property="MinWidth"
                Value="120" />
        <Setter Property="MinHeight"
                Value="20" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ComboBox}">
                    <Border BorderBrush="White"
                            BorderThickness="1">
                        <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition></ColumnDefinition>
                            <ColumnDefinition Width="Auto" MinWidth="30"></ColumnDefinition>
                        </Grid.ColumnDefinitions>
                            
                        <ToggleButton x:Name="ToggleButton"
                                      Template="{StaticResource ComboBoxToggleButton}"
                                      Grid.Column="1"
                                      Focusable="false"
                                      Cursor="Hand"
                                      ClickMode="Press"
                                      IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, 
                                      RelativeSource={RelativeSource TemplatedParent}}" />

                        <Border Background="White">
                            <TextBlock IsHitTestVisible="False"
                                        Text="{TemplateBinding SelectionBoxItem}"
                                        HorizontalAlignment="Center"
                                        FontSize="16"                                        
                                        Foreground="#38004D"></TextBlock>
                        </Border>                               

                        <Popup x:Name="Popup"
                               Placement="Bottom"
                               IsOpen="{TemplateBinding IsDropDownOpen}"
                               AllowsTransparency="True"
                               Focusable="False"
                               PopupAnimation="Slide">
                            <Border BorderBrush="White"
                                    BorderThickness="1,0,1,1">
                                <Grid x:Name="DropDown"
                                      SnapsToDevicePixels="True"
                                      MinWidth="{TemplateBinding ActualWidth}"
                                      MaxHeight="{TemplateBinding MaxDropDownHeight}">
                                    <Border x:Name="DropDownBorder"
                                            BorderThickness="1">
                                        <Border.BorderBrush>
                                            <SolidColorBrush Color="#38004D" />
                                        </Border.BorderBrush>
                                        <Border.Background>
                                            <SolidColorBrush Color="#38004D" />
                                        </Border.Background>
                                    </Border>
                                    <ScrollViewer Margin="4,6,4,6"
                                                  SnapsToDevicePixels="True">
                                        <StackPanel IsItemsHost="True"
                                                    KeyboardNavigation.DirectionalNavigation="Contained" />
                                    </ScrollViewer>
                                </Grid>
                            </Border>
                        </Popup>
                    </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="HasItems"
                                 Value="false">
                            <Setter TargetName="DropDownBorder"
                                    Property="MinHeight"
                                    Value="95" />
                        </Trigger>
                        <Trigger Property="IsGrouping"
                                 Value="true">
                            <Setter Property="ScrollViewer.CanContentScroll"
                                    Value="false" />
                        </Trigger>
                        <Trigger SourceName="Popup"
                                 Property="AllowsTransparency"
                                 Value="true">
                            <Setter TargetName="DropDownBorder"
                                    Property="CornerRadius"
                                    Value="4" />
                            <Setter TargetName="DropDownBorder"
                                    Property="Margin"
                                    Value="0,2,0,0" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="{x:Type ComboBoxItem}"
           TargetType="{x:Type ComboBoxItem}">
        <Setter Property="SnapsToDevicePixels"
                Value="true" />
        <Setter Property="OverridesDefaultStyle"
                Value="true" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ComboBoxItem}">
                    <Border x:Name="Bd"
                            Padding="2"
                            SnapsToDevicePixels="true"
                            Background="Transparent">
                        <TextBlock x:Name="Txt"
                                   Text="{TemplateBinding Content}"></TextBlock>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver"
                                 Value="True"
                                 SourceName="Bd">
                            <Setter Property="Background"
                                    Value="White"
                                    TargetName="Bd"></Setter>
                            <Setter Property="Foreground"
                                    Value="#38004D"
                                    TargetName="Txt"></Setter>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>